package com.example.win.android_banduyujia.peopleactivity.fragment.projectfragment.database;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.example.win.android_banduyujia.database.BaseDatabaseHelper;
import com.example.win.android_banduyujia.database.DBHelper;
import com.example.win.android_banduyujia.entity.CurrEntity;
import com.example.win.android_banduyujia.entity.MyProjectEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Win on 2015/9/20.
 */
public class MyCourseDatabase extends BaseDatabaseHelper {
     private static final String TABLE_NAME_MY_COURSE = "tb_my_course";

     private static MyCourseDatabase  mInstance;
    private List<CurrEntity> allCourse;

    public MyCourseDatabase(String tableName) {
        super(tableName);
    }

    public static MyCourseDatabase getInstance(){
         if(mInstance == null){
             mInstance = new MyCourseDatabase(TABLE_NAME_MY_COURSE);
         }
        return mInstance;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(String.format(SQL_CREATE_PROJECT, TABLE_NAME_MY_COURSE));
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
        db.execSQL(String.format(DBHelper.SQL_COURSE_FORMAT, TABLE_NAME_MY_COURSE));
        onCreate(db);
    }

    public boolean insert(MyProjectEntity entity){

        return true;
    }

    public void insertByList(List<MyProjectEntity> lists){
        for(MyProjectEntity entity:lists){
            insert(entity);
        }
    }

    public List<MyProjectEntity> getAllProject(){
        SQLiteDatabase db = null;
        Cursor  cursor = null;
        List<MyProjectEntity> list = new ArrayList<MyProjectEntity>();

        try {
            db = DBHelper.getInstance().getReadableDatabase();

            cursor=db.query(TABLE_NAME_MY_COURSE, null, null, null, null, null, null);
            while (cursor.moveToNext()){
                MyProjectEntity entity = getProjectInfo(cursor);
                list.add(entity);
            }
            return list;
        } catch (Exception e) {
            return list;
        }finally {
            if(cursor !=null)
                cursor.close();
        }
    }



    public List<MyProjectEntity> deleteOneProject(String id){

        return null;
    }

    public List<MyProjectEntity> deleteAllProject(){

        return null;
    }
}
